﻿@{
    Layout = "~/Views/Shared/_DialogLayout.cshtml";
}

<div class="dialog-content" style="margin-bottom:50px;">
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

    <input type="hidden" id="StatusList" name="StatusList" class="condfield" data-fieldname="StatusList" value="@ViewBag.Status" />
    <input type="hidden" id="Iswaitoutpart" name="Iswaitoutpart" class="condfield" data-fieldname="Iswaitoutpart" value="@ViewBag.Iswaitoutpart" />

    <div class="row nopadding">
        <div class="col-xs-5" data-autosize="true">
            <table id="datagrid1" style="height:300px;"></table>
        </div>
        <div class="col-xs-2" style="text-align:center;">
            <br /><br />
            <button id="btnadd" class="btn btn-small btn-default">@CSMSLang.Get("btn_addnew")@*添加*@</button><br />
            <button id="btndel" class="btn btn-small btn-danger">@CSMSLang.Get("btn_del")@*移除*@</button>
        </div>
        <div class="col-xs-5" data-autosize="true">
            <table id="datagrid2" style="height:300px;"></table>
        </div>
    </div>
</div>
<div class="dialog-footer">
    <button id="btnclose" class="btn btn-small btn-default">@CSMSLang.Get("btn_close")@*关闭*@</button>
    <button id="btnok" class="btn btn-small btn-primary">@CSMSLang.Get("btn_ok")@*确定*@</button>
</div>

@section scripts{
    <script type="text/javascript" src="~/Scripts/jquery.easyui.datagrid-dnd.js?ver=@WebApp.BLL.CommonStr.Ver"></script>
    <script type="text/javascript">
        //页面Key
        var pagekey = "@ViewBag.Pagekey";
        var usercols = @Html.Raw(ViewBag.UserCols);
        var cols = @Html.Raw(ViewBag.Cols);

        $(document).ready(function () {
            //关闭
            $("#btnclose").click(function (evt) { evt.preventDefault(); parent.closeDialog(); return false; });
            //保存
            $("#btnok").click(function (evt) {
                evt.preventDefault();

                layer.load(2);
                $.ajax({
                    type: "post",
                    url: baseurl + "Public/SaveUserColumn",
                    data: {
                        pagekey: pagekey,
                        json: JSON.stringify(usercols)
                    },
                    success: function (e) {
                        layer.closeAll();
                        
                        //parent.closeDialog(true);
                        parent.location.reload();
                    },
                    error: function (xhr) {
                        layer.closeAll();
                        showError(xhr);
                    }
                });
            });

            $("#btnadd").click(function (evt) {
                evt.preventDefault();
                
                var $dg = $("#datagrid1");
                var row = $dg.datagrid('getSelections');
                if (row.length == 0) {
                    $.messager.alert(csms_lang.message_info_title, csms_lang.message_please_choose_add_column, "warning");
                    return;
                }
                for (var i = row.length - 1; i >= 0; i--) {
                    $("#datagrid2").datagrid('appendRow', row[i]);
                    $("#datagrid2").datagrid("enableDnd");
                    
                    $dg.datagrid('deleteRow', $dg.datagrid("getRowIndex", row[i]));
                }
            });
            $("#btndel").click(function (evt) {
                evt.preventDefault();
                
                var $dg = $("#datagrid2");
                var row = $dg.datagrid('getSelections');
                if (row.length == 0) {
                    $.messager.alert(csms_lang.message_info_title, csms_lang.message_please_choose_delete_column, "warning");
                    return;
                }
                for (var i = row.length - 1; i >= 0; i--) {
                    $("#datagrid1").datagrid('appendRow', row[i]);
                    
                    $dg.datagrid('deleteRow', $dg.datagrid("getRowIndex", row[i]));
                }
            });

            LoadDatagrid1();
            LoadDatagrid2();
        });

        //加载列表数据
        function LoadDatagrid1() {
            var $dg = $("#datagrid1");
            $dg.datagrid({
                title: csms_lang.label_can_choose_column,
                fit: true,
                fitColumns: true,
                striped: true,
                nowrap: true,
                idField: 'Field',
                pagination: false,
                pageNumber: 1,
                pageSize: 100,
                pageList: [10, 20, 30, 50, 80, 100],
                rownumbers: true,
                singleSelect: false,
                sortName: 'Sort',
                sortOrder: 'asc',
                columns: [[
                    { field: "ck", title:"ck", checkbox: true, width: 30, align: 'left' },
                    { field: "Title", title:csms_lang.label_column_name, sortable: true, width: 200, align: 'left' }
                ]]
            }).datagrid("loadData", cols);
        }
        //加载列表数据
        function LoadDatagrid2() {
            var $dg = $("#datagrid2");
            $dg.datagrid({
                title:csms_lang.label_selected_column,
                fit: true,
                fitColumns: true,
                striped: true,
                nowrap: true,
                idField: 'Field',
                pagination: false,
                pageNumber: 1,
                pageSize: 100,
                pageList: [10, 20, 30, 50, 80, 100],
                rownumbers: true,
                singleSelect: false,
                sortName: 'Sort',
                sortOrder: 'asc',
                columns: [[
                    { field: "ck", title:"ck", checkbox: true, width: 30, align: 'left' },
                    { field: "Title", title:csms_lang.label_column_name, sortable: true, width: 200, align: 'left' }
                ]]
            }).datagrid("loadData", usercols);

            //$dg.datagrid("enableDnd");
        }
    </script>
}






